<?php
/**
 * Created by PhpStorm.
 * User: C。
 * Date: 2019/8/13
 * Time: 9:04
 */
namespace app\home\controller;

use app\common\model\MusicCate as MusicCateModel;
use app\common\model\Music as MusicModel;

/**
 * News资讯控制器
 * Class Banner
 * @package app\home\controller
 */
class Musiccate extends Base
{
    /**
     * [index  获取禅乐分类]
     * @param
     * @return json
     * @author [C。]
     */
    public function index()
    {
        $model = new MusicCateModel;
        $mmodel = new MusicModel;
        try{
            $musiccate = $model->getAllData(['class_id'=>4,'states'=>1],'sort','id,cname,sort,img','asc');
            foreach($musiccate as &$v){
                $music = $mmodel->getlists(['itemid'=>$v['id'],'states'=>1],0,3);
                $v['music'] = $music;
                $num1 = $mmodel->getSum(['itemid'=>$v['id'],'states'=>1],'jplay_num');
                $num2 = $mmodel->getSum(['itemid'=>$v['id'],'states'=>1],'play_num');
                $v['play_num'] = $num1 + $num2;
            }
        }catch (\Exception $e){
            systembug($e->getMessage(),2,$this->url);
            return admin_json(-1,$e->getMessage());
        }
        return admin_json(1,'获取成功',$musiccate);
    }
    /**
     * [catemusic  根据分类id获取音乐]
     * @param
     * @return json
     * @author [C。]
     */
    public function catemusic()
    {
        $param = input('param.');
        $mmodel = new MusicModel;
        try {
            $music = $mmodel->getlists(['itemid'=>$param['id'],'states'=>1],0,5);
            foreach($music as &$v){
                if(empty($v['author'])){
                    $v['author'] = '来自网络';
                }
            }
        } catch (\Exception $e) {
            systembug($e->getMessage(), 2, $this->url);
            return admin_json(-1, $e->getMessage());
        }
        return admin_json(1, '获取成功',$music);
    }
}